


layui.use(['form', 'tree', 'table', 'layedit', 'laydate', 'element'], function () {

    var element = layui.element,
        form = layui.form,
        upload = layui.upload,
        layedit = layui.layedit;
    form.on('submit(save)', function(data){
        var layerTips = parent.layer === undefined ? layui.layer : parent.layer;
        //layerTips.msg("url:"+$("#ImgPr").attr("src"));

        submitForm(data);
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('submit(cancel)', function(data){
        layer.confirm('确定取消吗？', null, function (index) {

            window.setTimeout(function () {
                parent.tab.deleteTab(parent.tab.getCurrentTabId(),true);
            },1000);
        });

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});

function submitForm(data){
    $.ajax({
        url: '/activityFetch/fetchJia',
        type: 'post',
        data: new FormData($("#form1")[0]), // serializes the form's elements.
        cache:false,
        contentType: false,
        processData: false,
        success: function (data) {
            var layerTips = parent.layer === undefined ? layui.layer : parent.layer;
            if(data.rel){
                layerTips.msg('采集任务启动成功');
                window.setTimeout(function () {
                    parent.tab.deleteTab(parent.tab.getCurrentTabId(),true);
                },1000);
            }else{
                layerTips.msg(data.msg);
            }
        }
    });
}
